import 'package:flu_framework/res/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

enum StateType {
  STATE_NO_DATA,
  STATE_NO_NET,
  STATE_NO_LOGIN,
  STATE_NORMAL
}

extension AAA on StateType{
  String get img => <String>[
    'images/need_login_icon.png',
    'images/icon_no_network.png',
    'images/need_login_icon.png',
    ''
  ][index];

  String get hintText => <String>[
    '您尚未购买课程',
    '无网络服务',
    '请登录后查看您的课程表',
    ''
  ][index];
}

typedef DoSomething = Function();

class StateLayout extends StatelessWidget {

  StateType type;
  DoSomething? doSomething;
  String? btText;
  StateLayout(this.type,{Key? key,this.doSomething,this.btText}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      color: Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Image.asset(type.img,),
          SizedBox(height: 15,),
          Text(
            type.hintText,
            style: TextStyle(color: ZXColors.text_black_65,fontSize: 14),
          ),
          SizedBox(height: 15,),
          if(type == StateType.STATE_NO_DATA || type == StateType.STATE_NO_LOGIN) ElevatedButton(onPressed: (){
            doSomething?.call();
          }, child: Text(this.btText??""),style: ElevatedButton.styleFrom(
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)) ,
            backgroundColor: ZXColors.bg_bt_red
          ),
          )
        ],
      ),
    );
  }
}

